<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ include file="/jsp/common/common.jsp"%>

<html>
<head>
<base target="_self" />
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<title></title>
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
<link rel="Stylesheet" type="text/css"
	href="<c:url value="/static/css/jquery.ui.css"/>" />
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/json2.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/common.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/showMsg.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/listBox/jquery.clever.listbox.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/jsp/storemanage/supplier/addStoreMater.js"/>"></script>
<script type="text/javascript">
	function initList(listDisplayEId) {
		$('#' + listDisplayEId).datagrid({
			nowrap : false,
			striped : true,
			collapsible : true,
			remoteSort : true,
			notSelectByRow : false,
			/* frozenColumns : [ [ {
				field : 'ids',
				checkbox : true
			} ] ], */
			onLoadError : function() {
				$.messager.alert('错误', '获取数据失败，请与管理员联系！', 'error');
			},
			onClickRow : function(rowIndex) {
				$(".myrad").prop("checked", false);
				$(".myrad").eq(rowIndex).prop("checked", true);
				$('#listDisplay').datagrid('beginEdit', rowIndex);
			}
		});
	};
	function initList2(listDisplayEId) {
		$('#' + listDisplayEId).datagrid({
			nowrap : false,
			striped : true,
			collapsible : true,
			remoteSort : true,
			notSelectByRow : false,
			/* frozenColumns : [ [ {
			    field : 'ids',
			    checkbox : true
			} ] ], */
			onLoadError : function() {
				$.messager.alert('错误', '获取数据失败，请与管理员联系！', 'error');
			},
			onClickRow : function(rowIndex) {
				$(".myrad").prop("checked", false);
				$(".myrad").eq(rowIndex).prop("checked", true);
				$('#listDisplay2').datagrid('beginEdit', rowIndex);
			}
		});
	};
	$(document).ready(function() {
		document.getElementById('supId').value = '';
	    document.getElementById('supId1').value = '';
        document.getElementById('bilu').style.display = 'none';
		document.getElementById('zzy').style.display = 'none';
	    document.getElementById('zzy2').style.display = 'none';
	    initeDocument();
		initList('listDisplay');
		initList2('listDisplay2');
		
        var storeInId = GetQueryString("storeInId");
        
        if(storeInId!=null){
        	document.getElementById('storeInId').value = storeInId;
        	search4();
        }

	});

	function addStore() {
		$('#AddStoreForm').form('submit', {
			url : '<c:url value='/store/addStore.do'/>', //查询提交路径
			onSubmit : function()//提交按钮相应函数
			{
				return $('#AddStoreForm').form('validate');
			},
			success : function(data) {
				data = eval("(" + data + ")");
				if (data.success) {
					$.messager.alert("提示", "提交成功！", 'info');
				} else {
					$.messager.alert("提示", data.msg, 'warning');
				}
				
			},
			error : function() {
				$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
				return;
			}
		});

	}
	function search1() {
		if ($('#date1').datebox('getValue') == '') {
			alert("订单日不能为空");
		} else {
			$('#listDisplay').datagrid('load', {
				initFlag : 1,
				date : $('#date1').datebox('getValue'),
				materType : $('#materType').combobox('getValue')
			});
		}

	}
	function search2() {
		var supId1 = document.getElementById("supId1").value;
        if (supId1 == '' || supId1==0) {
            alert("请选择供货商！");
            return ;
        }else{
        	$('#listDisplay').datagrid('load', {
                initFlag : 3,
                supId : supId1,
                materType : $('#materType1').combobox('getValue')
            });
        }
    }
	function search3() {
		var rows = $('#listDisplay').datagrid('getRows');
		for (var i = 0; i < rows.length; i++) {
			var rowIndex = $('#listDisplay').datagrid('getRowIndex',
					rows[i]['materId']);
			$('#listDisplay').datagrid('endEdit', rowIndex);
			//alert(getMaterValueCost(rows[i]['materId']));
			rows[i]['materValueUndressed'] = getMaterValueCost(rows[i]['materId']);
			$('#listDisplay').datagrid('refreshRow', i);
		}
	}
	function search4() {
		var storeInId=document.getElementById('storeInId').value;
		if(storeInId ==0 ||storeInId=='' ||storeInId == 'undefined'){
			alert("请填写入库单号！");
			return ;
		}
		
		//删除所有行
		deleteAllRow('#listDisplay2');
		$.ajax({
            type : 'post',
            async : false,
            url : "<c:url value='/storeSupplier/getStoreInDetail.do'/>" + "?storeInId=" + storeInId,
            dataType : "json",// 设置查询参数及提交路径
            success : function(data) {
                if (typeof (data) == 'string') {
                    data = JSON.parse(data);
                }
                if (data.success) {
                	for ( var i in data.StoreInDetailedVoList) {
                		$('#listDisplay2').datagrid('appendRow', {
                             materId : data.StoreInDetailedVoList[i].materId,
                             materName : data.StoreInDetailedVoList[i].materName,
                             materNum : data.StoreInDetailedVoList[i].materNum,
                             unit :  data.StoreInDetailedVoList[i].unit,
                             materValueUndressed : data.StoreInDetailedVoList[i].materValueUnit,
                             materType : data.StoreInDetailedVoList[i].materType,
                             brands : data.StoreInDetailedVoList[i].brands,
                             specifications : data.StoreInDetailedVoList[i].specifications
                         });
					}
                   
                }
            },
            error : function() {
                $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
            }
        });
	}
	function getMaterValueCost(materId) {
		var returnString;
		$.ajax({
			async : false,
			url : "<c:url value='/supplier/getMaterValueCostByMaterId.do'/>"
					+ "?materId=" + materId,
			type : "post",
			success : function(data) {
				if (typeof (data) == 'string') {
					data = JSON.parse(data);
				}
				returnString = data.materValueCost;
			}
		});
		return returnString;
	}
	function initeDocument() {
		// 下拉框选择控件，下拉框的内容是动态查询数据库信息  
		$("#supName").textbox({
			buttonText : '选择',
			iconCls : 'icon-man',
			iconAlign : 'left',
			editable : false,
			value : "全部",
			onClickButton : function() {

				initDateLeft();
				showMsgLeft();
				ShowDiv();

				var left = $('#left').listbox();
				var items = left.getDatas();
				left.removeRange(items);

				var right = $('#right').listbox();
				var itemsr = right.getDatas();
				right.removeRange(itemsr);

				$('#left').listbox().reload({
					data : dataLeft,
					ajaxsettings : {
						data : {
							id : 'a'
						}
					}
				});
			}
		});
		$("#supName1").textbox({
            buttonText : '选择',
            iconCls : 'icon-man',
            iconAlign : 'left',
            editable : false,
            value : "全部",
            onClickButton : function() {

                initDateLeft();
                showMsgLeft();
                ShowDiv();

                var left = $('#left').listbox();
                var items = left.getDatas();
                left.removeRange(items);

                var right = $('#right').listbox();
                var itemsr = right.getDatas();
                right.removeRange(itemsr);

                $('#left').listbox().reload({
                    data : dataLeft,
                    ajaxsettings : {
                        data : {
                            id : 'a'
                        }
                    }
                });
            }
        });
		$('#supMaterType').combobox({
			url : "<c:url value='/mater/pulldownMaterType.do?space=1'/>",
			editable : true, //不可编辑状态  
			cache : false,
			panelHeight : '150',
			valueField : 'materType',
			textField : 'materTypename',
		});

		$('#materType').combobox({
			url : "<c:url value='/mater/pulldownMaterType.do?space=1'/>",
			editable : true, //不可编辑状态  
			cache : false,
            width :'100px',
			panelHeight : '150',
			valueField : 'materType',
			textField : 'materTypename',
			value : 0
		});
		
		$('#materType1').combobox({
            url : "<c:url value='/mater/pulldownMaterType.do?space=1'/>",
            editable : true, //不可编辑状态  
            cache : false,
            width :'100px',
            panelHeight : '150',
            valueField : 'materType',
            textField : 'materTypename',
            value : 0
        });
	}
	//获取data 数据
	var dataLeft;
	function initDateLeft() {
		$.ajax({
			async : false,
			url : "<c:url value='/supplier/getAllSup.do'/>",
			type : "post",
			success : function(data) {
				dataLeft = data;
				if (typeof (dataLeft) == 'string' && dataLeft != '') {
					dataLeft = JSON.parse(dataLeft);
				}
			}
		});
	}
	function ShowDiv() {
		var Allwidth = '100%';
		var Allheight = '100%';
		document.getElementById('zzy').style.display = '';
		Loading.Show({
			width : Allwidth,
			height : Allheight
		});
	}
	//初始化showMsg
	function showMsgLeft() {
		$('#left').listbox({
			data : dataLeft,
			height : 300,
			width : 200,
			dndscope : 'demo',
			dnd : false,
			multiselect : true,
			selectchange : function(data) {
				if (data && data.length > 0) {
					$('#btnRight').attr('disabled', false);
				} else {
					$('#btnRight').attr('disabled', true);
				}
			}
		});
		$('#right').listbox({
			//data: data,
			height : 300,
			width : 200,
			dndscope : 'demo',
			dnd : true,
			multiselect : true
		});
		$('#btnRightAll').click(function() {
			var left = $('#left').listbox();
			var items = left.getDatas();
			left.clear();
			$('#right').listbox().addRange(items);
		});
		$('#btnLeftAll').click(function() {
			var right = $('#right').listbox();
			var items = right.getDatas();
			right.clear();
			$('#left').listbox().addRange(items);
		});
		$('#btnRight').click(function() {
			var left = $('#left').listbox();
			var items = left.getSelected();
			left.removeRange(items);
			$('#right').listbox().addRange(items);
		});
		$('#btnLeft').click(function() {
			var right = $('#right').listbox();
			var items = right.getSelected();
			right.removeRange(items);
			$('#left').listbox().addRange(items);
		});
		$('#btnRemove').click(function() {
			$('#right').listbox().removeRange([ {
				value : 2
			}, {
				value : 26
			} ]);
		});
		$('#btnSelect').click(function() {
			var selected = $('#right').listbox().getSelected();
			var msg = 'Selected count is: ' + selected.length;
			if (selected.length > 0) {
				msg += ', The first item text is: ' + selected[0].text;
			}
			msg += '.';
			alert(msg);
		});
		$('#btnGetItems').click(function() {
			var selected = $('#right').listbox('getDatas');
			alert('Items count is: ' + selected.length);
		});
		$('#btnSetSelection').click(function() {
			$('#left').listbox('setSelection', 1);
		});
		$('#select').click(function() {
			Loading.Hide();
			document.getElementById('zzy').style.display = 'none';

			var right = $('#right').listbox();
			var items = right.getDatas();
			var userNames = '';
			var userIds = '';
			if (items.length == 1) {
				for ( var e in items) {
					userNames = userNames + items[e].text + ',';
					userIds = userIds + items[e].value + ',';
				}
				userNames = userNames.substring(0, userNames.length - 1);
				userIds = userIds.substring(0, userIds.length - 1);

				if (userNames != '' && userIds != '') {
					$('#supName').textbox('setValue', userNames);
					document.getElementById('supId').value = userIds;
					
					$('#supName1').textbox('setValue', userNames);
                    document.getElementById('supId1').value = userIds;
				} else {
					$('#supName').textbox('setValue', '全部');
					document.getElementById('supId').value = '';
					
					$('#supName1').textbox('setValue', '全部');
                    document.getElementById('supId1').value = '';
				}
			} else {
				alert("供货商请选择一家！");
			}

		});
		$('#noselect').click(function() {
			Loading.Hide();
			document.getElementById('zzy').style.display = 'none';
		});
	}
	

	// 初始化showMsg
	function showMsgLeft2() {
	    $('#left2').listbox({
	        data : dataLeft,
	        height : 300,
	        width : 500,
	        dndscope : 'demo',
	        dnd : false,
	        multiselect : true,
	        selectchange : function(data) {
	            if (data && data.length > 0) {
	                $('#btnRight').attr('disabled', false);
	            } else {
	                $('#btnRight').attr('disabled', true);
	            }
	        }
	    });
	    var data = [ {
	        value : 10,
	        text : 'think8848'
	    }, {
	        value : 20,
	        text : 'aCloud'
	    }, {
	        value : 21,
	        text : 'aaaaa'
	    }, {
	        value : 36,
	        text : 'qqqqq'
	    } ];
	    $('#right2').listbox({
	        // data: data,
	        height : 300,
	        width : 500,
	        dndscope : 'demo',
	        dnd : true,
	        multiselect : true
	    });
	    $('#btnRightAll2').click(function() {
	        var left = $('#left2').listbox();
	        var items = left.getDatas();
	        left.clear();
	        $('#right2').listbox().addRange(items);
	    });
	    $('#btnLeftAll2').click(function() {
	        var right = $('#right2').listbox();
	        var items = right.getDatas();
	        right.clear();
	        $('#left2').listbox().addRange(items);
	    });
	    $('#btnRight2').click(function() {
	        var left = $('#left2').listbox();
	        var items = left.getSelected();
	        left.removeRange(items);
	        $('#right2').listbox().addRange(items);
	    });
	    $('#btnLeft2').click(function() {
	        var right = $('#right2').listbox();
	        var items = right.getSelected();
	        right.removeRange(items);
	        $('#left2').listbox().addRange(items);
	    });
	    $('#btnRemove2').click(function() {
	        $('#right2').listbox().removeRange([ {
	            value : 2
	        }, {
	            value : 26
	        } ]);
	    });
	    $('#btnSelect2').click(function() {
	        var selected = $('#right2').listbox().getSelected();
	        var msg = 'Selected count is: ' + selected.length;
	        if (selected.length > 0) {
	            msg += ', The first item text is: ' + selected[0].text;
	        }
	        msg += '.';
	        alert(msg);
	    });
	    $('#btnGetItems2').click(function() {
	        var selected = $('#right2').listbox('getDatas');
	        alert('Items count is: ' + selected.length);
	    });
	    $('#btnSetSelection2').click(function() {
	        $('#left2').listbox('setSelection', 1);
	    });
	    $('#select2').click(function() {
	        Loading.Hide();
	        document.getElementById('zzy2').style.display = 'none';
	        
	        var right = $('#right2').listbox();
	        var items = right.getDatas();

	        if (items.length > 0) {
	        	//检验是否入库单已有材料
	        	for ( var e in items) {
	                if(!checkMater(items[e].value)){
	                    alert("材料["+items[e].text+"]已在清单中！");
	                    return false;
	                }
	        	}
	            for ( var e in items) {
	                var str = "materId=" + items[e].value;
	                $.ajax({
	                    type : 'post',
	                    async : false,
	                    url : "<c:url value='/mater/getMaterPo.do'/>" + "?" + str,
	                    dataType : "json",// 设置查询参数及提交路径
	                    success : function(data) {
	                    	if (typeof (data) == 'string') {
	                            data = JSON.parse(data);
	                        }
	                        if (data.success) {
	                            $('#listDisplay2').datagrid('appendRow', {
	                                materId : data.materPo.materId,
	                                materName : data.materPo.materName,
	                                materNum : 0,
	                                unit : data.materPo.unit,
	                                materValueUndressed : 0,
	                                materType : data.materPo.materType,
	                                brands : data.materPo.brands,
	                                specifications : data.materPo.specifications
	                            });
	                        }
	                    },
	                    error : function() {
	                        $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
	                    }
	                });

	            }
	        }

	        var itemsr = right.getDatas();
	        right.removeRange(itemsr);

	    });
	    $('#noselect2').click(function() {
	        Loading.Hide();
	        document.getElementById('zzy2').style.display = 'none';
	    });
	}
    function checkMater(materId){
    	var rowIndex =$('#listDisplay2').datagrid('getRowIndex',materId);
    	if(rowIndex==-1){
    		return true;
    	}else{
    		return false;
    	}
    }
	function searchSupByMaterType() {
		$('#searchFormForShowCust').form('submit', {
			url : '<c:url value='/supplier/getSupByMaterType.do'/>', //查询提交路径
			onSubmit : function()//提交按钮相应函数
			{
				return $('#searchFormForShowCust').form('validate');
			},
			success : function(data) {
				data = eval("(" + data + ")");
				/* var left = $('#left').listbox();
				var items = left.getDatas();
				left.removeRange(items); */

				/* var right = $('#right').listbox();
				var itemsr = right.getDatas();
				right.removeRange(itemsr); */
				$('#left').listbox().reload({
					data : data,
					ajaxsettings : {
						data : {
							id : 'a'
						}
					}
				});
			},
			error : function() {
				$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
				return;
			}
		});
	}

	function formatJiantou(val, rowData, rowIndex) {
		return "<a href='###' onclick='shoppingStore("
				+ rowIndex
				+ ")'><img height='30' width='80' src='../../../images/jiantou.jpg'/></a>";
	}
	
	
	function shoppingStore(rowIndex){
        var rowData ;
        var a ;
        var dateone;
        $('#listDisplay').datagrid('endEdit', rowIndex);
        var rowDateAll = $('#listDisplay').datagrid('getRows');
        for(var i=0; i<rowDateAll.length; i++){
            if(rowIndex ==$('#listDisplay').datagrid('getRowIndex',rowDateAll[i]['materId'])) {
            	
                $('#listDisplay').datagrid('endEdit', rowIndex);
                rowData = rowDateAll[i];
                if(!checkMater(rowData['materId'])){
                	$.messager.alert('提示',"此材料已在清单中！",'info');
                    return false;
                }
                if ( !isNumberAndNoZero(rowData['materNum'])  ){
                    $.messager.alert('提示',"材料"+rowData['materName']+"，数量请填写数字！",'info');
                    return false;
                }
                var materIdDate = rowData['materId'];
                var materNumDate = rowData['materNum'];
                var unitDate = rowData['unit'];
                var materValueUndressedDate = rowData['materValueUndressed'];
                var materNameDate = rowData['materName'];
                var materTypeDate = rowData['materType'];
                var brandsDate = rowData['brands'];
                var specificationsDate = rowData['specifications'];

                $('#listDisplay2').datagrid('appendRow', {
                    materId : materIdDate,
                    materNum : materNumDate,
                    unit : unitDate,
                    materValueUndressed : materValueUndressedDate,
                    materName : materNameDate,
                    materType : materTypeDate,
                    brands : brandsDate,
                    specifications : specificationsDate
                });
                break;
            }
        }
       
    }
	
	//附属材料查询模块
    function searchInfoForShowCust2() {

        var materId = document.getElementById("materIdForSearch2").value;
        if (materId == '') {
            materId = 0;
        }

        var form = new FormData();
        form.append("materId", materId); // 可以增加表单数据
        form.append("materName", document.getElementById("materName2").value); // 可以增加表单数据
        xhr2 = new XMLHttpRequest();
        xhr2.onreadystatechange = state_ChangeT;
        // xhr.setRequestHeader("Accept", "text/plain")
        xhr2
                .open(
                        "post",
                        '<c:url value='/supplierDistribute/checkSupplierDistributeForGather.do'/>',
                        true);
        xhr2.send(form);
    }
    function state_ChangeT() {
        if (xhr2.readyState == 4) {// 4 = "loaded"

            if (xhr2.status == 200) {// 200 = OK
                var data;
                data = xhr2.responseText;
                if (typeof (data) == 'string' && data != '') {
                    data = JSON.parse(data);
                }
                var a = data.stringJson;
                if (typeof (dataLeft) == 'string' && dataLeft != '') {
                    a = JSON.parse(dataLeft);
                }
                $('#left2').listbox().reload({
                    data : a,
                    ajaxsettings : {
                        data : {
                            id : 'a'
                        }
                    }
                });
            } else {
                alert("Problem retrieving XML data");
            }
        }
    }
    var xhrAddStoreIn = new XMLHttpRequest();
    function addStoreIn(){
    	 var supId = document.getElementById("supId").value;
         if (supId == '' || supId==0) {
             alert("请选择供货商！");
             return ;
         }
         
         if($('#date2').datebox('getValue') ==''){
             $.messager.alert('提示','入库日期没有填写！','info');
             return ;
         }

         var row = $('#listDisplay2').datagrid('getRows');   
         if(row.length == 0){
             $.messager.alert('提示','入库列表中没有材料！','info');
             return;
         }else{
             var materList = new Array(); 
             var jsonFater;
             for (var i = 0 ; i < row.length;i++){
            	 var rowIndex = $("#listDisplay2").datagrid('getRowIndex', row[i]["materId"]);
                 $("#listDisplay2").datagrid('endEdit', rowIndex);
                 
                 if ( !isNumberAndNoZero(row[i]['materNum'])  ){
                     $.messager.alert('提示',"材料"+row[i]['materName']+"，数量请填写数字！",'info');
                     return false;
                 }
                 
                 if ( !isNumberAndNoZero(row[i]['materValueUndressed'])  ){
                     $.messager.alert('提示',"材料"+row[i]['materName']+"，单价请填写数字！",'info');
                     return false;
                 }
                 
                 var jsonSun = "{materId:'"+row[i]['materId']+"',materValueUndressed:'"+row[i]['materValueUndressed']+"',materNum:'"+row[i]['materNum']+"'}";
                 materList.push(jsonSun);
                 $("#listDisplay2").datagrid('beginEdit', rowIndex);
             }
         }
         jsonFater = JSON.stringify(materList);
         var form = new FormData();
         form.append("supSupId", supId); // 可以增加表单数据
         form.append("materdategridList", jsonFater+''); // 可以增加表单数据
         form.append("creatDate", $('#date2').datebox('getValue')); // 可以增加表单数据

         
         xhrAddStoreIn.onreadystatechange = xhrAddStoreIn_return;
         xhrAddStoreIn.open(
                         "post",
                         '<c:url value='/storeSupplier/addStoreInForSup.do'/>',
                         true);
         xhrAddStoreIn.send(form);
    }
    function xhrAddStoreIn_return(){
    	if (xhrAddStoreIn.readyState == 4) {// 4 = "loaded"
            if (xhrAddStoreIn.status == 200) {// 200 = OK
                var data;
                data = xhrAddStoreIn.responseText;
                if (typeof (data) == 'string' && data != '') {
                    data = JSON.parse(data);
                }
                if(data.success){
                	alert("生成入库单！");
                    deleteAllRow('#listDisplay2');
                    $('#date2').datebox('setValue','');
                    document.getElementById("supId").value =0;
                    $("#supName").textbox('setValue','无');

                }
            } else {
                alert("Problem retrieving XML data");
            }
        }
    }
    
    var xhrUpStoreIn = new XMLHttpRequest();
    function updateStoreIn(){
        var storeInId = document.getElementById("storeInId").value;
        if (storeInId == '' || storeInId==0) {
            alert("入库单号不能为空！");
            return ;
        }

        var row = $('#listDisplay2').datagrid('getRows');   
        if(row.length == 0){
            $.messager.alert('提示','入库列表中没有材料！','info');
            return;
        }else{
            var materList = new Array(); 
            var jsonFater;
            for (var i = 0 ; i < row.length;i++){
                var rowIndex = $("#listDisplay2").datagrid('getRowIndex', row[i]["materId"]);
                $("#listDisplay2").datagrid('endEdit', rowIndex);
                
                if ( !isNumberAndNoZero(row[i]['materNum'])  ){
                    $.messager.alert('提示',"材料"+row[i]['materName']+"，数量请填写数字！",'info');
                    return false;
                }
                
                if ( !isNumberAndNoZero(row[i]['materValueUndressed'])  ){
                    $.messager.alert('提示',"材料"+row[i]['materName']+"，单价请填写数字！",'info');
                    return false;
                }
                
                var jsonSun = "{materId:'"+row[i]['materId']+"',materValueUndressed:'"+row[i]['materValueUndressed']+"',materNum:'"+row[i]['materNum']+"'}";
                materList.push(jsonSun);
                $("#listDisplay2").datagrid('beginEdit', rowIndex);
            }
        }
        jsonFater = JSON.stringify(materList);
        var form = new FormData();
        form.append("storeInId", storeInId); // 可以增加表单数据
        form.append("materdategridList", jsonFater+''); // 可以增加表单数据
        form.append("creatDate", $('#date2').datebox('getValue')); // 可以增加表单数据
        
        xhrUpStoreIn.onreadystatechange = xhrUpStoreIn_return;
        xhrUpStoreIn.open(
                        "post",
                        '<c:url value='/storeSupplier/updateStoreInForSup.do'/>',
                        true);
        xhrUpStoreIn.send(form);
    }
    function xhrUpStoreIn_return(){
       if (xhrUpStoreIn.readyState == 4) {// 4 = "loaded"
           if (xhrUpStoreIn.status == 200) {// 200 = OK
               var data;
               data = xhrUpStoreIn.responseText;
               if (typeof (data) == 'string' && data != '') {
                   data = JSON.parse(data);
               }
               if(data.success){
                   alert("成功修改入库单！");
                   deleteAllRow('#listDisplay2');
                   $('#date2').datebox('setValue','');
                   document.getElementById("supId").value =0;
                   $("#supName").textbox('setValue','无');

               }
           } else {
               alert("Problem retrieving XML data");
           }
       }
    }
    //删除选择行
    function deleteRow(){
    	var rows = $('#listDisplay2').datagrid('getSelections');
        if(rows.length == 0){
            $.messager.alert('提示','请选择一条记录操作！','info');
            return;
        } else {
        	var length = rows.length -1;
            for (var i = length; i > -1; i--) {
                var rowIndex = $('#listDisplay2').datagrid('getRowIndex',
                        rows[i]['materId']);
                $('#listDisplay2').datagrid('deleteRow', rowIndex);
            }
        }
    }
    //更具表名 删除所有行
    function deleteAllRow(list){
        var rows = $(list).datagrid('getRows');
        if(rows.length == 0){
            return;
        } else {
            var length = rows.length -1;
            for (var i = length; i > -1; i--) {
                var rowIndex = $(list).datagrid('getRowIndex',
                        rows[i]['materId']);
                $(list).datagrid('deleteRow', rowIndex);
            }
        }
    }
    //计算总价 显示也页脚
    function sumValue(){
        var row = $('#listDisplay2').datagrid('getRows');
        if( row.length == 0 ){
            return;
        } else {
        	
        	var materValueAllFoot = 0;
            for (var i = 0 ; i < row.length;i++){
                var rowIndex = $("#listDisplay2").datagrid('getRowIndex', row[i]["materId"]);
                $("#listDisplay2").datagrid('endEdit', rowIndex);
                row[i]['materValueAll'] = decimal(row[i]['materNum']*row[i]['materValueUndressed'],2);
                materValueAllFoot= materValueAllFoot+row[i]['materValueAll'];
                $('#listDisplay2').datagrid('refreshRow', rowIndex);
                $("#listDisplay2").datagrid('beginEdit', rowIndex);
            }
            materValueAllFoot = decimal(materValueAllFoot,2);
            $('#listDisplay2').datagrid('reloadFooter',[
                {unit: '总价', materValueAll: materValueAllFoot}
            ]);

        }
    	
    }
</script>
</head>
<body>
	<table width="98%">
		<tr>
			<td id='bilu'>
				<form id="AddStoreForm" name="AddStoreForm" method="post">

					<div 
						style="height: auto; width: 1180px; background: #fafafa; padding: 2px;"
						class="easyui-panel" title="&nbsp&nbsp&nbsp&nbsp&nbsp必录信息"
						collapsible="true" minimizable="false" maximizable="false"
						closable="false">
						<table cellpadding="5">
							<tr>
								<td><input class="easyui-validatebox" type="hidden" name="supId" id="supId" editable="false"  /></td>
							</tr>
							<tr>
                                <td><input class="easyui-validatebox" type="hidden" name="supId1" id="supId1" editable="false"  /></td>
                            </tr>
							<tr>
								<td><input class="easyui-validatebox" type="hidden" name="materdategridList" /></td>
							</tr>
						</table>
					</div>
				</form>
			</td>
		</tr>
		
	</table>
	<table width="100%">
		<tr>
			<td width="50%" valign="top">
				<table width="100%">
					<tr style="height: 12px;"></tr>
					<tr>
						<td>
							<table id="listDisplay" title="材料列表" iconCls="icon-list"
								singleSelect="false" idField="materId"
								url="<c:url value="/storeSupplier/findMaterByDateAndMaterType.do"/>"
								loadMsg="请稍候......" pagination="false" pageSize="20"
								pageList="[10,20,30,40,50,100]" sortName="materId" rownumbers="true"
								toolbar="#tb" sortOrder="asc">
								<thead>
									<tr>
										<th field="materRole" width="25" align="center"
											checkbox="true" hidden="true"></th>
										<th field="materId" width="50" sortable="true">材料ID
										</th>
										<th field="materNum" width="40" sortable="true" editor="text"
											align="center">数量</th>
										<th field="unit" width="50" sortable="true">单位</th>
										<th field="materValueUndressed" width="60" sortable="true"
											editor="text" align="right">价格</th>
										<th field="materName" width="140" sortable="true">材料名</th>
										<th field="materType" width="60" formatter="formatFoodType1"
											sortable="true">种类</th>
										<th field="brands" width="50" sortable="true">品牌</th>
										<th field="specifications" width="60" sortable="true">规格</th>
										<th field="jiantou" width="100" sortable="true"
											formatter="formatJiantou">加入库存清单</th>

										<!-- <th field="materLevel" width="50" formatter="formatFoodType"
                                sortable="true" hidden="true">品级</th> -->
										<!-- <th field="supId" width="80" sortable="true" hidden="true">供货商ID
                            </th>
                            <th field="supName" width="80" sortable="true">供货商名</th> -->

									</tr>
								</thead>
							</table>
						</td>
					</tr>
				</table>
			</td>
			<td width="50%" valign="top">
				<table width="100%">
					<tr style="height: 12px;"></tr>
					<tr>
						<td>
							<table id="listDisplay2" title="入库列表" iconCls="icon-list"
								singleSelect="false" idField="materId"
								loadMsg="请稍候......" pagination="false" pageSize="20"
								pageList="[10,20,30,40,50,100]" sortName="materId" rownumbers="true"
								toolbar="#tb2" sortOrder="asc" showFooter="true">
								<thead>
									<tr>
										<th field="materRole" width="25" align="center"
											checkbox="true" ></th>
										<th field="materId" width="40" sortable="true" hidden="true">材料ID
										</th>
										<th field="materNum" width="40" sortable="true" editor="text"
											align="center">数量</th>
										<th field="unit" width="50" sortable="true">单位</th>
										<th field="materValueUndressed" width="60" sortable="true"
											editor="text" align="right">价格</th>
										<th field="materName" width="140" sortable="true">材料名</th>
										<th field="materType" width="60" formatter="formatFoodType1"
											sortable="true">种类</th>
										<th field="brands" width="50" sortable="true">品牌</th>
										<th field="specifications" width="60" sortable="true">规格</th>
										<th field="materValueAll" width="60" sortable="true">总价格</th>
										<!-- <th field="materLevel" width="50" formatter="formatFoodType"
                                sortable="true" hidden="true">品级</th> -->
										<!-- <th field="supId" width="80" sortable="true" hidden="true">供货商ID
                            </th>
                            <th field="supName" width="80" sortable="true">供货商名</th> -->

									</tr>
								</thead>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>

	<div
		style='position: absolute; left: 40px; top: 40px; z-index: 101; background-color: #FFFFFF; border-radius: 10px; width: 550px;'
		id="zzy">
		<table align="center">
			<tr>
				<td colspan="3">
					<form id="searchFormForShowCust" name="searchFormForShowCust"
						method="post" accept-charset="UTF-8">
						<div
							style="height: auto; width: 470px; background: #fafafa; padding: 5px;"
							class="easyui-panel" title="查询" iconCls="icon-search"
							collapsible="true" minimizable="false" maximizable="false"
							closable="false">
							<table>
								<tr>
									<td>供货种类:</td>
									<td><input class="easyui-combobox" name="supMaterType"
										id="supMaterType" required="true" /></td>
									<td colspan="2"><a href="#" class="easyui-linkbutton"
										data-options="iconCls:'icon-search'" style="width: 60px"
										onclick="searchSupByMaterType()">查询</a></td>
								</tr>
							</table>
						</div>
					</form>
				</td>
			</tr>
			<tr>
				<td>
					<ul id="left">
					</ul>
				</td>
				<td><input type="button" value="&gt;&gt;" id="btnRightAll"
					style="width: 50px;" /><br /> <input type="button" value="&gt;"
					id="btnRight" style="width: 50px;" /><br /> <input type="button"
					value="&lt;" id="btnLeft" style="width: 50px;" /><br /> <input
					type="button" value="&lt;&lt;" id="btnLeftAll" style="width: 50px;" />
				</td>
				<td>
					<ul id="right">
					</ul>
				</td>
			</tr>
		</table>
		<table align="center">
			<tr>
				<!--  
                <td><input type="button" value="Add Item" id="btnAdd" /></td>
                <td><input type="button" value="Remove Item" id="btnRemove" /></td>
                <td><input type="button" value="Get Select" id="btnSelect" /></td>
                <td><input type="button" value="Get Items" id="btnGetItems" /></td>
                <td><input type="button" value="SetSelection (value equal to '1')" id="btnSetSelection" /></td>
                <td><input type="button" value="Reload" id="btnReload" /></td>
                -->
				<td><input type="button" value="取消" id="noselect" /></td>
				<td width="200px"></td>
				<td><input type="button" value="选择" id="select" /></td>

			</tr>
		</table>
	</div>
	<div
        style='position: absolute; left: 40px; top: 40px; z-index: 101; background-color: #FFFFFF; border-radius: 10px; width: 1200px;'
        id="zzy2">
        <table align="center">
            <tr>
                <td colspan="3">
                    <form id="searchFormForShowCust" name="searchFormForShowCust"
                        method="post" accept-charset="UTF-8">
                        <div
                            style="height: auto; width: 1000px; background: #fafafa; padding: 5px;"
                            class="easyui-panel" title="查询" iconCls="icon-search"
                            collapsible="true" minimizable="false" maximizable="false"
                            closable="false">
                            <table>
                                <tr>
                                    <td>材料id:</td>
                                    <td><input class="easyui-validatebox" name="materIdForSearch2"
                                        id="materIdForSearch2" /></td>
                                    <td>材料名称:</td>
                                    <td><input class="easyui-validatebox" name="materName2"
                                        id="materName2" /></td>
                                    <td><a href="#" class="easyui-linkbutton"
                                        data-options="iconCls:'icon-search'" style="width: 60px"
                                        onclick="searchInfoForShowCust2()">查询</a></td>
                                    <td><input type="hidden" name="materdategridList"
                                        id="materdategridList" /></td>

                                </tr>
                            </table>
                        </div>
                    </form>
                </td>
            </tr>
            <tr>
                <td>
                    <ul id="left2">
                    </ul>
                </td>
                <td><input type="button" value="&gt;&gt;" id="btnRightAll2"style="width: 50px;" /><br />
                    <input type="button" value="&gt;" id="btnRight2" style="width: 50px;" /><br /> 
                    <input type="button" value="&lt;" id="btnLeft2" style="width: 50px;" /><br /> 
                    <input type="button" value="&lt;&lt;" id="btnLeftAll2" style="width: 50px;" />
                </td>
                <td>
                    <ul id="right2">
                    </ul>
                </td>
            </tr>
        </table>
        <table align="center">
            <tr>
                <!--  
                <td><input type="button" value="Add Item" id="btnAdd" /></td>
                <td><input type="button" value="Remove Item" id="btnRemove" /></td>
                <td><input type="button" value="Get Select" id="btnSelect" /></td>
                <td><input type="button" value="Get Items" id="btnGetItems" /></td>
                <td><input type="button" value="SetSelection (value equal to '1')" id="btnSetSelection" /></td>
                <td><input type="button" value="Reload" id="btnReload" /></td>
                -->
                <td><input type="button" value="取消" id="noselect2" /></td>
                <td width="200px"></td>
                <td><input type="button" value="选择" id="select2" /></td>

            </tr>
        </table>
    </div>
	<div id="tb" style="padding: 5px; height: auto">
		<div>
			<table>
				<tr>
					<td width="70">订单日期：</td>
					<td align="left"><input class="easyui-datebox" id="date1"
						name="date1"></td>
					<td>种类：</td>
					<td><input class="easyui-combobox" name="materType"
						id="materType"></td>

					<td><a href="#" onclick="search1()" class="easyui-linkbutton"
						iconCls="icon-search" plain="true">根据订单查询材料</a></td>
				</tr>
				<tr>
				    <td width="70">供货商：</td>
                    <td><input name="supName1" id="supName1" editable="false" data-options="required:true" /></td>
				    <td>种类：</td>
                    <td><input class="easyui-combobox" name="materType1"
                        id="materType1"></td>
                    <td colspan="1"><a href="#" onclick="search2()" class="easyui-linkbutton"
                        iconCls="icon-search" plain="true">根据供货商和种类查询材料</a></td>
                </tr>
				<tr>
					<td colspan="2"><a href="#" onclick="search3()"
						class="easyui-linkbutton" iconCls="icon-search" plain="true">检索最后一次材料价格</a></a></td>
				</tr>
				
			</table>
		</div>
		<div style="margin-bottom: 5px"></div>
	</div>

	<div id="tb2" style="padding: 5px; height: auto">
		<div>
			<table>
				<tr>
                    <td width="70">供货商：</td>
                    <td><input name="supName" id="supName" editable="false" data-options="required:true" /></td>
					<td width="70" align="center">入库日期：</td>
                    <td align="left"><input class="easyui-datebox" id="date2" name="date2"></td>
                    <td colspan="1"><a href="#" onclick="addStoreIn()" class="easyui-linkbutton" iconCls="icon-ok" plain="true">新增入库单</a></td>
				</tr>
				<tr>
                    <td width="70">进货单号：</td>
                    <td><input name="storeInId" id="storeInId" editable="false" data-options="required:true" /></td>
                    <td colspan="2"><a href="#" onclick="search4()" class="easyui-linkbutton" iconCls="icon-search" plain="true">加载进货单</a></a></td>
                    <td colspan="1"><a href="#" onclick="updateStoreIn()" class="easyui-linkbutton" iconCls="icon-ok" plain="true">修改入库单</a></td>
                     
                </tr>
				<tr>
                    <td colspan="2"><a href="#" onclick="addMaterRow()"
                        class="easyui-linkbutton" iconCls="icon-add" plain="true">增加入库货品</a></td>
                    <td colspan="2"><a href="#" onclick="deleteRow()" class="easyui-linkbutton"
                        iconCls="icon-remove" plain="true">删除入库货品</a></td>
                    <td colspan="1"><a href="#" onclick="sumValue()" class="easyui-linkbutton"
                        iconCls="icon-sum" plain="true">核算总价</a></td>
                </tr>
				<tr>
                    
                </tr>
			</table>
		</div>
		<div style="margin-bottom: 5px"></div>
	</div>
</body>
</html>